﻿@using kangsuce.Model

@{
    ViewBag.Title = "管理员角色";
}

<div class="wrapper wrapper-content animated fadeInUp">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>角色分配 <small></small></h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">角色</label>
                            <div class="col-sm-10">
                                @foreach (KSC_Role item in ViewBag.List)
                                {
                                    <label class="checkbox-inline i-checks">
                                        <input type="checkbox" class="role" @(item.roleDisplay == "1" ? "checked" : "") value="@item.roleId">@item.roleName
                                    </label>
                                }
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-2">
                                <button class="btn btn-primary" id="btn_Submit" type="button">保存内容</button>
                                <button class="btn btn-white" id="btn_Back" type="button">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

@section Js{
    <script type="text/javascript">
        $(function () {
            var urlParms = getRequest();
            $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green" });
            $("small").text("（" + decodeURIComponent(urlParms.userName) + "）");
            $("#btn_Submit").click(function() {

                if ($(".role:checked").length == 0) {
                    layer.msg("至少选择一个角色", { time: 2000 });
                    return;
                }
                var ids = '';
                $.each($(".role:checked"), function (index, item) {
                    var id = $(item).val();
                    ids += ',' + id;
                });
                ids = ids.slice(1);
                $.post("/Account/SysUserRoleSave", { roleIds: ids, userId: urlParms.userId }, function (json) {
                    if (json.result == "success") {
                        var backUrl = $.getUrlParam("backUrl");
                        layer.msg("保存成功", { icon: 1, time: 2000 }, function() {
                            location.href = backUrl;
                        });
                    } else {
                        layer.msg(json.msg, { icon: 5, time: 2000 });
                    }
                }, 'json');
            });

            $("#btn_Back").click(function() {
                location.href =urlParms.backUrl;
            });
        });

        function getRequest() {

            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
    </script>
}
